package com.itmk.web.user.service.impl;

//import com.itmk.utils.Base64;
import java.util.Base64;
import com.itmk.web.adminInfo.entity.AdminInfo;
import com.itmk.web.ai.entity.Pdfs;
import com.itmk.web.companyInfo.entity.Company;
import com.itmk.web.user.entity.UserLogin;
import com.itmk.web.user.mapper.UserMapper;
import com.itmk.web.user.service.UserService;
import com.itmk.web.userInfo.entity.BasicInfo;
import com.itmk.web.userInfo.entity.EducationInfo;
import com.itmk.web.userInfo.entity.ForjobInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserServiceImpl implements UserService {

    //加盐
    private static final String B64 = "...ASEDcdthvfdWERVDDGHBfdrhgdjbfdr";

    @Autowired
    private UserMapper userMapper;
    @Override
    public UserLogin getUser(String phone) {
        //解密
        UserLogin userLogin = userMapper.getUser(phone);
        if(userLogin!=null){
            byte[] password1 = Base64.getDecoder().decode(userLogin.getPassword());
            String password = new String(password1);
            String[] pwsCode = password.split("[...]");
            userLogin.setPassword(pwsCode[0]);
        }
        return userLogin;
    }

    @Override
    public void addUser(String phone, String password,String signType,String uuid) {
        //加密
        String pwCode = Base64.getEncoder().encodeToString((password+B64).getBytes());
        userMapper.addUser(phone, pwCode, signType,uuid);
    }

    @Override
    public void addBasicInfo(BasicInfo candidate) {

        //加密
        String pwCode = Base64.getEncoder().encodeToString((candidate.getPassword()+B64).getBytes());

        userMapper.addCandidate(candidate.getPhone(),pwCode,candidate.getUuid(),candidate.getSignType());
    }

    @Override
    public void addCompany(Company company) {
        int zero = 0;
        userMapper.addCompany(company.getPhone(),company.getUuid(),zero);
    }

    @Override
    public void addAdminInfo(AdminInfo administrator) {
        userMapper.addAdministrator(administrator.getPhone(),administrator.getUuid());
    }

    @Override
    public void addEducationInfo(EducationInfo educationInfo) {
        userMapper.addEducationInfo(educationInfo.getUuid());
    }

    @Override
    public void addForjobInfo(ForjobInfo forjobInfo) {
        userMapper.addForjobInfo(forjobInfo.getUuid());
    }

    @Override
    public void addToken(String token) {
        userMapper.addToken(token);
    }

    @Override
    public Boolean deleteToken(String token) {
        return userMapper.deleteToken(token);
    }

    @Override
    public void addUUID(String uuid) {
        userMapper.addUUID(uuid);
    }

    @Override
    public Boolean deleteUUID(String uuid) {
        return  userMapper.deleteUUID(uuid);
    }

    @Override
    public void addResume(Pdfs pdfs) {
        userMapper.addResume(pdfs);
    }
}
